package cameras;

import guiobjects.Observation;

public class SquareCam extends AbstractCamera
{
	int myMod, myRemainder;
	double myStartX, myEndX, myStartY, myEndY;
	public SquareCam(double startX, double endX, double startY, double endY, int mod, int remainder)
	{
		myStartX = startX;
		myEndX = endX;
		myStartY = startY;
		myEndY = endY;
		myMod = mod;
		myRemainder = remainder;
	}
	@Override
	public boolean hasInView(Observation i) 
	{
		return (i.x < myEndX) && (i.x > myStartX) && (i.z < myEndY) && (i.z > myStartY);
	}
	@Override
	public boolean hasInView(double x, double y) {
		return (x < myEndX) && (x > myStartX) && (y < myEndY) && (y > myStartY);
	}
	@Override
	public boolean isCorrectFrame(int frame) {
		return (frame % myMod == myRemainder);
	}
	@Override
	public double distanceToOutsideCam(Observation i) {
		if (hasInView(i))
			return Math.min(Math.min(i.x - myStartX, myEndX - i.x), Math.min(i.z - myStartY, myEndY - i.z));
		if ((i.x < myEndX) && (i.x > myStartX))
			return -1 * Math.min(Math.abs(i.z - myEndY), Math.abs(i.z - myStartY));
		if ((i.z < myEndY) && (i.z > myStartY))
			return -1 * Math.min(Math.abs(i.x - myEndX), Math.abs(i.x - myStartX));
		return -1 * Math.pow(Math.pow(Math.min(Math.abs(i.z - myEndY), Math.abs(i.z - myStartY)),2)
				+ Math.pow(Math.min(Math.abs(i.x - myEndX), Math.abs(i.x - myStartX)), 2), 0.5);
	}
}
